package cn.wizzer.app.user.modules.models.vo;

import cn.wizzer.app.match.modules.models.vo.MatchVO;
import lombok.Data;
import org.nutz.json.Json;

import java.io.Serializable;
import java.util.*;

/**
 * @ClassName LiveAnchors
 * @Description 赛事对应主播信息
 * @Author 阿强
 * @Date 2019/12/129:15
 * @Version 1.0
 */
@Data
public class MatchLives implements Serializable {

    public MatchLives(){};

    public MatchLives(MatchVO match, LiveInfo... anchors) {
        this.match = match;
        this.anchors = new HashSet<>();
        if (null!=anchors&&anchors.length!=0){
            for (int i = anchors.length - 1; i >= 0; i--) {
                this.anchors.add(anchors[i]);
            }
        }
    }

    private MatchVO match;

    private Set<LiveInfo> anchors;

    public MatchLives addAnchors(LiveInfo liveInfo){
        if (this.anchors == null){
            anchors = new HashSet<>();
        }
        anchors.add(liveInfo);
        return this;
    };
    public MatchLives addAnchors(Set<LiveInfo> liveInfos){
        if (this.anchors == null){
            anchors = liveInfos;
        }
        else {
            anchors.addAll(liveInfos);
        }
        return this;
    };

    public MatchLives removeAnchors(LiveInfo liveInfo){
        if (this.anchors != null){
            anchors.remove(liveInfo);
        }
        return this;
    };

    @Override
    public String toString() {
        return Json.toJson(this);
    }

    public long getMatchDate() {
        return match.getDatetime().getTime();
    }
}
